Skip to content

Add intercept api command #9552

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged

Conversation

asirvadAbrahamVarghese
Copy link
Contributor

@asirvadAbrahamVarghese asirvadAbrahamVarghese commented Aug 12, 2025

PR to add new command to intercept apis that handles duplicate intercepts (Follow up work from: #9546 as suggested here)

Before:

Intercepted with alias 'editEventForServer' in the beforeEach block:
image

Intercepting the same endpoint with 'editEventForServer' as alias again later in the test:
image

Or intercepting the same endpoint with a different alias 'editEventForServerSecond':
image

After:

Intercepted with alias 'editEventForServer' in the beforeEach block:
image
'editEventForServer' will be intercepted by default since its in the same scope as that of beforeEach, only wait for that alias is required:
image

@miq-bot assign @jrafanie
@miq-bot add-label cypress
@miq-bot add-label test

@asirvadAbrahamVarghese
Copy link
Contributor Author

Further thoughts for enhancement:

  • Command is made with AI with some tweaks - to manage state alternate to Cypress.env would be cy.task like in this example
  • If there's a way to control when cy.wait(alias) is executed, ideally, only when the request is actually made, API intercepts can be handled within support commands (e.g., via cy.selectAccordion() using a global pattern to match all treeSelect endpoints, so individual tests don’t need to manually intercept or wait for treeSelect APIs). One possible approach is to leverage event listeners or callbacks that fire when an intercept occurs.

@jrafanie
Copy link
Member

Close / open after revert of #9505 via #9553

@jrafanie jrafanie closed this Aug 13, 2025
@jrafanie jrafanie reopened this Aug 13, 2025
Copy link
Member

@jrafanie jrafanie left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like this a lot. For a followup, what are your thoughts on providing reader and reset functions for the interceptedAliases?

In other words:

Before

// reader function:
expect(Cypress.env('interceptedAliases')).to.include.all.keys(...);

// reset function for the before/after
Cypress.env('interceptedAliases', {})

After

// reader function:
expect(cy.interceptApiAliases()).to.include.all.keys(...);

// reset function for the before/after
cy.interceptApiReset()

@jrafanie jrafanie merged commit e157b37 into ManageIQ:master Aug 13, 2025
36 of 38 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants